<?php
/**
 *
 * 版权所有：顺势网站管理系统<qwadmin.qiawei.com>

 * 日    期：2016-09-20
 * 版    本：1.0.0
 * 功能说明：后台首页控制器。
 *
 **/

namespace Qwadmin\Controller;

class IndexController extends ComController
{
    public function index()
    {
        if(isAdmin()){
            $this->assign('admin', 1);
        }else{
            $this->assign('admin', 0);
        }
        $p = isset($_GET['p']) ? intval($_GET['p']) : '1';
        $t = time() - 3600 * 24 * 60;
        $message = M('message');
        $pagesize = 25;#每页数量
        $offset = $pagesize * ($p - 1);//计算记录偏移量
        $count = $message->count();
        $list = $message->order('id desc')->limit($offset . ',' . $pagesize)->select();
        if(!empty($list)){
            foreach ($list as $key=>$val){
               if(empty($val['qd'])){
                    $list[$key]["qd"] = "自然渠道";
                }
            }
        }
        $page = new \Think\Page($count, $pagesize);
        $page = $page->show();
        $this->assign('list', $list);
        $this->assign('page', $page);
        $this->assign('nav', array('', '', ''));//导航
        $this->display();
    }

    public function export(){

        $bg = isset($_GET['bg']) ? $_GET['bg'] : '';
        $end = isset($_GET['end']) ? $_GET['end'] : false;
        if(empty($bg) || empty($end)){
            $this->error('请选择时间后再导出！');
        }
        $bgTime = $bg." 00:00:00";
        $endTime = $end."  23:59:59";
        $where = "deleted = 0 AND ctime >= '".$bgTime."' AND ctime <= '".$endTime."'";
        $message = M('message');
        $list = $message->where($where)->field("id,name,mobile,money,qd,ctime")->select();
        if(!empty($list)){

            $head = array("序号","姓名","电话","借款金额","渠道","时间");
            $filename = "用户贷款信息".date('Ymd');
            $this->exporttocsv($list,$filename,$head);
        }

    }


}